﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using WPFExcelReport.Helpers;
using System.Collections;
using System.Collections.Generic;
namespace WPFExcelReport
{
    public partial class TBB02
    {
        public string LP="" ,ZH="",HX="";
         

        #region ==dwBW===========
        public static readonly DependencyProperty dwBWProperty = DependencyProperty.Register("dwBW",
            typeof(DataRow), typeof(TBB02),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwBWChanged));
        public DataRow dwBW
        {
            get
            {
                return (DataRow)GetValue(dwBWProperty);
            }
            set
            {
                SetValue(dwBWProperty, value);
            }
        }
        private static void OndwBWChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TBB02;
            if (src != null)
            {
                src.dwBW = (DataRow)e.NewValue;
            }
        }
        #endregion 

        ITXEXRPT ITXEXRPT; 
        public TBB02()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VBABST ();
            this.DataContext = MV;
            InitializeComponent();
           
        }
         
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            base.Window_Loaded(sender, e);
        } 

        private void txtZH_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                QueryCommand(null, null);
            }
        }

        public override void QueryCommand(object sender, System.Windows.RoutedEventArgs e)
        { 
            
           
            LP = txtLP.Text.ToString().Trim();
            ZH = txtZH.Text.ToString().Trim();
            HX = txtHX.Text.ToString().Trim(); 
            dwData = MV.SetProd.Tables["BABST"].NewRow();
            dwData["BMLP"] = LP;
            dwData["BMKART"] = ZH;
            dwData["BMFARBE"] = HX; 
            try
            {
                SResult = TMV.QBABST07(dwData);
                MergeData(SResult, true, true);
                
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }  

        public override void PrintCommand(object sender, RoutedEventArgs e)
        {
            try
            {
                if (ITXEXRPT == null)
                {
                    ITXEXRPT = new ITXEXRPT();
                    ITXEXRPT.Root = "C:\\IntexReport";
                    ITXEXRPT.strCompany = app.company;
                    ITXEXRPT.PrintType = "OpenExcel";
                }
                ITXEXRPT.dsSource = new DataSet();
                ITXEXRPT.dsSource.Merge(MV.SetProd);
                //ITXEXRPT.dsSource.Merge(Se.Env);

                ITXEXRPT.DocType = "JLTBB02";

                ITXEXRPT.strExcelFile = @"JLT\JLTBB02.xls";
                string filename = ITXEXRPT.WriteExcelReport();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        
         
    }
}
